package BeenChina.PM.Action; 
import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
 
import BeenChina.PM.Model.ModelErrorChildImage;   
import BeenChina.PM.Service.ServiceFactory;
import BeenChina.PM.Util.JqGridBaseAction;
import BeenChina.PM.Util.StringUtil;

public class ErrorChildImageManageAction extends JqGridBaseAction<ModelErrorChildImage> {
	private static final long serialVersionUID = 1L;
	private List<ModelErrorChildImage> errorImageList =new ArrayList<ModelErrorChildImage>();	
	private String	dateFrom,dateTo ;
	private String oper;
	private String id,finalResult,correctEntryResult,audit,correctCommentID; 
	

	public void setCorrectCommentID(String correctCommentID) {
		this.correctCommentID = correctCommentID;
	}	 
	
	public String getAudit() {
		
		if (audit.equals("on"))
			return "1";
		return "0";
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public void setCorrectEntryResult(String correctEntryResult)
	{
		this.correctEntryResult = correctEntryResult;
	}
	
	public void setAudit(String audit)
	{
		this.audit = audit;
	}
 

	public void setFinalResult(String finalResult) {
		this.finalResult = finalResult;
	}

	public void setOper(String value)
	{
		oper = value;
	}
	
	public void setDateFrom(String dateFrom){
		this.dateFrom = dateFrom;
	}
	
	public void setDateTo(String dateTo){
		this.dateTo = dateTo;
	} 
	
	@Override
	public int getResultSize() {
		return this.errorImageList.size();  
	}

	@Override
	public List<ModelErrorChildImage> listResults(int from, int length) throws Exception { 
		try{
			 if (StringUtil.isDate(dateFrom) &&   StringUtil.isDate(dateTo)  ){
				  errorImageList =
					 	 ServiceFactory.getInstance().getQualityInfoService().selectErrorChildImage(dateFrom, dateTo);
			 }
			return errorImageList;
		}
		catch(Exception exp){
			 throw exp;
		}		 		  
	}	
	
	 @Override
	public String execute() {
		 
		//setCaseList(this.caseList);
		return "load";
	}
	 
	 public String Modify()
	 {
		 String result = ActionSupport.SUCCESS;	
		 if(oper != null && oper.equals("edit")){ 
			   
			 updateChildImage();
			  
		  }
		 
		 return result;
	 }
	 
	 private Integer updateChildImage()
	 {				 
		 return ServiceFactory.getInstance().getQualityInfoService()
				 .updateFinalResult(id, finalResult,correctEntryResult,correctCommentID,getAudit());		 
		 
	 }
}